package com.asset.service.imp;

import com.asset.dao.BranchOfficeMapper;
import com.asset.pojo.BranchOffice;
import com.asset.pojo.User;
import com.asset.service.BaseService;
import com.asset.service.UserService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by gongshaobo on 2017/1/9  10:59.
 */
@Service
public class UserServiceImp extends BaseService implements UserService {
    @Override
    public void addUser(User user){
        userMapper.addUser(user);
    }
    @Override
    public void modifyUser(User user){
        userMapper.editUser(user);
    }
    @Override
    public List<User> listUser(String name,Integer index,Integer length){
        List<User> userList = userMapper.listUser(name,index,length);
        for(User u : userList){
            BranchOffice branchOffice = branchOfficeMapper.getBranchOffice(u.getBranchOffice());
            u.setOffice(branchOffice);
        }
        return userList;
    }
    @Override
    public User getUserById(Long id){
        User user = userMapper.getUserById(id);
        BranchOffice branchOffice = branchOfficeMapper.getBranchOffice(user.getBranchOffice());
        user.setOffice(branchOffice);
        return user;
    }
    @Override
    public User getUserByLoginInfo(String name,String password){
        return userMapper.getUserByLoginInfo(name,password);
    }
}
